package vip.xiaonuo.modular.qiniu;

import com.qiniu.common.QiniuException;
import com.qiniu.storage.DownloadUrl;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.pojo.response.ResponseData;

/**
 * @Author liuwenli
 * @Version 1.0
 * @CreateTime 2022-03-25 22:14
 * @Description 七牛api调用接口
 */
@RestController
@RequestMapping("/qiniu")
public class QiniuAPIController {

    @Value("${qiniu.accessKey}")
    private String accessKey;
    @Value("${qiniu.secretKey}")
    private String secretKey;
    @Value("${qiniu.bucket}")
    private String bucket;
    @Value("${qiniu.domain}")
    private String domain;

    @GetMapping("/getUploadToken")
    public ResponseData getuploadToken() {
        Auth auth = Auth.create(accessKey, secretKey);
        String upToken = auth.uploadToken(bucket);
        return ResponseData.success(upToken);
    }

/*    @GetMapping("/getFileUrl")
    public ResponseData getFileUrl(String key) throws QiniuException {
        // domain   下载 domain, eg: qiniu.com【必须】
        // useHttps 是否使用 https【必须】
        // key      下载资源在七牛云存储的 key【必须】
        DownloadUrl url = new DownloadUrl(domain, false, key);
*//*        url.setAttname(attname) // 配置 attname
                .setFop(fop) // 配置 fop
                .setStyle(style, styleSeparator, styleParam) // 配置 style*//*
        // 带有效期
        long deadline = System.currentTimeMillis() / 1000 + 3600;
        long expireInSeconds = 3600;//1小时，可以自定义链接过期时间
        Auth auth = Auth.create(accessKey, secretKey);
        return ResponseData.success(url.buildURL(auth, deadline));
    }*/
}
